<?php

/**
 * Форма голосования
 */
class PollsForm extends Zend_Form {

    /**
     * Форма голосования
     *
     * @param int $sid #ID секции
     * @param int $pid #ID голосования
     * @return NewsForm
     */
    public function newPoll($sid = 0) {
        $this->setName('poll');
        $t = Zend_Registry::get('Zend_Locale');
        $this->setDefaultTranslator($t);
        $question = new Zend_Form_Element_Text('question');
        $question->setLabel('Question')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->setRequired();

        $description = new Zend_Form_Element_Textarea('description');
        $description->setLabel('Description')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

        $active = new Zend_Form_Element_Checkbox('active');
        $active->setLabel('Active')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

        $answers = array();
        $answer = new Zend_Form_Element_Text('answer');
        $answer->setLabel('Answers')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->setRequired();

        $answer2 = new Zend_Form_Element_Text('answer2');
        $answer2->setLabel('Add answer')
                ->setAttrib('class', 'poll_add_answer')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

        $answers[] = $answer;
        $answers[] = $answer2;

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Save');
        $submit->setAttrib('id', 'submitbutton');

        $this->addElements(array_merge(array($question, $description), $answers, array($active, $submit)));

        $this->addDisplayGroup(array('question', 'description'), 'poll', array('legend' => $t->_('Poll')));
        $this->addDisplayGroup(array('answer', 'answer2'), 'answers', array('legend' => $t->_('Answers')));
        $this->addDisplayGroup(array('active', 'submit'), 'settings', array('legend' => $t->_('Settings')));
        $this->setDisplayGroupDecorators(array(
            'FormElements',
            'Fieldset'
        ));

        $this->setAction(ADMIN_URL . '/pages/modify/id/' . $sid . '/a/new');
        return $this;
    }

    /**
     * Форма голосования
     *
     * @param int $sid #ID секции
     * @param int $pid #ID голосования
     * @param array $data Ответы на голосование
     * @return NewsForm
     */
    public function editPoll($sid, $pid) {
        $this->setName('poll');
        $t = Zend_Registry::get('Zend_Locale');
        $this->setDefaultTranslator($t);
        $question = new Zend_Form_Element_Text('question');
        $question->setLabel('Question')
                ->addFilter('StripTags')
                ->addFilter('StringTrim')
                ->setRequired();

        $description = new Zend_Form_Element_Textarea('description');
        $description->setLabel('Description')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

        $active = new Zend_Form_Element_Checkbox('active');
        $active->setLabel('Active')
                ->addFilter('StripTags')
                ->addFilter('StringTrim');

        $submit = new Zend_Form_Element_Submit('submit');
        $submit->setLabel('Save');
        $submit->setAttrib('id', 'submitbutton');

        $this->addElements(array($question, $description, $active, $submit));

        $this->addDisplayGroup(array('question', 'description'), 'main', array('legend' => $t->_('Poll')));
        $this->addDisplayGroup(array('active', 'submit'), 'settings', array('legend' => $t->_('Settings')));
        $this->setDisplayGroupDecorators(array(
            'FormElements',
            'Fieldset'
        ));

        $this->setAction(ADMIN_URL . '/pages/modify/id/' . $sid . '/a/edit/pid/' . $pid);
        return $this;
    }

}